package com.wantup.controller;

import com.wantup.controller.v1.GameInfoController;
import com.wantup.model.InMessage;
import com.wantup.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping(value = "/test")
public class TestController {

//    @Autowired
//    private GameInfoController gameInfoController;

    /**
     * 该用 消息模板进行 消息的推送
     */
    @Autowired
    private WebSocketService webSocketService;


    @RequestMapping(value = "/")
    public String test(){
        return "Hello word";
    }


//    /**
//     * 测试 不能通过
//     * @return
//     */
//    @RequestMapping(value = "/sendWebSocketMess")
//    @SendTo("/topic2/game_chat")
//    public String sendWebSocketMess(){
//        InMessage inMessage = new InMessage();
//        inMessage.setContent("你好呀 朋友");
//
//        gameInfoController.getMessage(inMessage);
//
//        return "sendWebSocketMess";
//    }

        @RequestMapping(value = "/sendWebSocketMess")
        public String sendWebSocketMess(){
        InMessage inMessage = new InMessage();
        inMessage.setContent("你好呀 朋友");

        webSocketService.sendTopicMessage("/topic2/game_rank",inMessage);

        return "sendWebSocketMess";
    }

}
